/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __WOW_ARCHIVE_H__
#define __WOW_ARCHIVE_H__

#include "MPQArchive.h"
#include "WOWDbcFile.h"

#include "BLPFile.h"
#include "M2File.h"
#include "M2SkinFile.h"
#include "M2AnimFile.h"
#include "WdtFile.h"
#include "WdlFile.h"

namespace PQGameCore
{
	class WOWArchive
	{
	public:
		typedef std::vector<MPQArchive*> MPQArchiveList;
		typedef std::map<std::string,MPQFile*> MPQFileList;
		
	protected:
		WOWArchive();
	public:
		static WOWArchive& getSingleton()
		{
			static WOWArchive inst;
			return inst;
		}

		void init();

		std::vector<std::string> getFileList(std::string path="/");
		
		MPQFile* openMPQFile(std::string path);
		void closeMPQFile(std::string path);

		bool isLeafPath(std::string path);
		bool fileExist(std::string path);

		WOWDbcFile* openDbcFile(std::string path);
		M2File* openM2File(std::string path);
		M2SkinFile* openM2SkinFile(std::string path);
		BLPFile* openBLPFile(std::string path);
		M2AnimFile* openM2AnimFile(std::string path);

		void convertChrModels();
		
		WdtFile* getWdtFile(int index);
		WdlFile* getWdlFile(int index);
	private:
		void initMPQArchive(std::string path);
		void initDatabases();
	private:
		MPQArchiveList _list;
		MPQFileList _fileList;
	};
}

#define SWOWArchive PQGameCore::WOWArchive::getSingleton()

#endif
